package com.oceansoft.mobile.biz.api.controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.oceansoft.mobile.biz.api.entity.WxDict;
import com.oceansoft.mobile.biz.api.service.IApiWxDictService;
import com.oceansoft.mobile.common.Constant;
import com.oceansoft.mobile.common.util.HttpClientUtil;
import com.oceansoft.mobile.common.util.Result;

@Controller
@RequestMapping("api/wxDict")
public class ApiWxDictController {
	@Resource
	private IApiWxDictService apiWxDictService;
	
	
	@ResponseBody
	@RequestMapping("parent/{id}")
	public Result getByParentId(@PathVariable("id") int id,HttpServletRequest request){
		request.getSession().setAttribute("hkyslid",id);
		List<WxDict> list=apiWxDictService.getByParentId(id);
		Result r=new Result();
		r.setData(list);
		return r;
	}
	@ResponseBody
	@RequestMapping("policestation")
	public Result getPoliceStation(@RequestParam("casename") String casename,@RequestParam("depcode") String depcode){
		String url = Constant.host5 + "api/police/PoliceByCasename";
		Result r = null;
		JSONObject param = new JSONObject();
    	param.put("casename",casename);
    	param.put("hierarchy",depcode);
    	try {
			r = HttpClientUtil.doGAUrlPost(url, param);
		} catch (IOException e) {
				e.printStackTrace();
		}
		return r;
	}
	@ResponseBody
	@RequestMapping("material")
	public Result getMaterial(@RequestParam("casename") String casename,@RequestParam("orgid") String orgid,HttpServletRequest request){
		String url = Constant.host5 + "api/SXInfo/GetSXInfoBy?caseName="+casename+"&orgGuid="+orgid;
		Result r = null;
    	try {
			r = HttpClientUtil.doGAGet(url);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return r;
	}

	@ResponseBody
	@RequestMapping("ywms/{casename}")
	public Result ywms(@PathVariable("casename") String casename) throws SQLException{
		System.out.print("=====casename======"+casename);
		WxDict list=apiWxDictService.getYwms(casename);
		System.out.print("?????????WxDict:::"+list);
		Result r=new Result();
		r.setData(list);
		//Result r=new Result();
		return r;
	}

}
